<template>
    <div class="mobile-page" :style="{width:magicWidth+'%',margin:slider+'px auto 0'}">
        <img v-if="fullImg" class="home_img" :src="fullImg" />
        <div class="home_magic fullbox">
            <div :class="{uitem:true,ignore:uItem.img?true:false}" v-for="(uItem,uidx) in urlList" :style="{left:uItem.info[0].width[0]+'%',width:(uItem.info[0].width[1]-uItem.info[0].width[0])+'%',top:uItem.info[1].width[0]+'%',height:(uItem.info[1].width[1]-uItem.info[1].width[0])+'%',}">
                <img v-if="uItem.img" :src="uItem.img" class="uimg">
                <div class="fullbox wd">{{uItem.url}}</div>
            </div>
        </div>
    </div>
</template>

<script>
    import { mapState } from 'vuex'
    export default {
        name: 'home_magic',
        cname: '魔方布局',
        icon: 'iconhuodongmofang',
        configName: 'c_home_magic',
        type:0,// 0 基础组件 1 营销组件 2工具组件
        defaultName:'magicBox', // 外面匹配名称
        props: {
            index: {
                type: null
            },
            num: {
                type: null
            }
        },
        computed: {
            ...mapState('admin/mobildConfig', ['defaultArray'])
        },
        watch: {
            pageData: {
                handler (nVal, oVal) {
                    this.setConfig(nVal)
                },
                deep: true
            },
            num: {
                handler (nVal, oVal) {
                    let data = this.$store.state.admin.mobildConfig.defaultArray[nVal]
                    this.setConfig(data)
                },
                deep: true
            },
            'defaultArray': {
                handler (nVal, oVal) {
                    let data = this.$store.state.admin.mobildConfig.defaultArray[this.num]
                    this.setConfig(data);
                },
                deep: true
            }
        },
        data () {
            return {
                // 默认初始化数据禁止修改
                defaultConfig: {
                    name:'magicBox',
                    timestamp: this.num,
                    // 页面间距
                    mbConfig: {
                        title: '页面间距',
                        val: 0,
                        min: -50
                    },
                    imgConfig: {
                        title: '背景图',
                        img: ''
                    },
                    wdConfig: {
                        title: '宽度(%)',
                        val: 100,
                        min: 0
                    },
                    flexConfig:{
                        title:'图片锚点<small style="margin-left:10px;">当锚点位置是图片时高度失效</small>',
                        list: [{
                                info:[{
                                    title:'宽度',
                                    width:[25,75]
                                },{
                                    title:'高度',
                                    width:[25,75]
                                }],
                                img: '',
                                url:''
                        }],
                    }
                },
                /*vuexMenu: '',
                txtColor: '',
                boxStyle: '',*/
                slider: '',
                magicWidth:'',//魔方宽度
                fullImg:'',//内容图片，
                urlList:[],
                pageData: {}
            }
        },
        mounted () {
            this.$nextTick(() => {
                this.pageData = this.$store.state.admin.mobildConfig.defaultArray[this.num]
                this.setConfig(this.pageData)
            })
        },
        methods: {
            setConfig (data) {
                if(!data) return
                this.slider = data.mbConfig.val;          
                this.magicWidth = data.wdConfig.val;
                this.urlList = data.flexConfig.list;
                this.fullImg = data.imgConfig.img;
            }
        }
    }
</script>

<style scoped lang="stylus">
.mobile-page
  position relative
  min-height 80px
  background-color rgba(253, 219, 178,0.6)
.home_img
    position relative
    width 100%
.home_empty
    position relative
    width 100%
    height 188px
.uitem 
    background-color rgba(0,0,0,0.6)
    border 1px dashed #f00
    position absolute
    
    color #fff
    width 50%
    left 25%
    top 25%
    height 50% 
    .wd
       display flex
       align-items center
       justify-content center
       word-break break-all
    .uimg
      position relative
      width 100%
.uitem.ignore
    height auto!important
</style>
